// axios 响应拦截 事件 发布订阅

type EventName = 'API:ERROR' | 'API:TIMEOUT' | 'API:OVERDUE';

class AxiosEventEmitter {
    private listeners: Record<EventName, Set<Function>> = {
        'API:ERROR': new Set(),
        'API:OVERDUE': new Set(),
        'API:TIMEOUT': new Set(),
    };

    on(eventName: EventName, listeners: Function) {
        this.listeners[eventName].add(listeners);
    }

    emit(eventName: EventName, ...args: any[]) {
        this.listeners[eventName].forEach((listeners) => listeners(...args));
    }
}

export default new AxiosEventEmitter();
